import os
import csv, sys

data = open(sys.argv[1], 'rb')
reader = csv.DictReader(data, delimiter=',')

avg=[]
aavg=[]
std=[]
gencount=[]
for row in reader:
    print row
    avg.append(float(row[' GENAVG']))
    if row[' ADJAVG'] not in [None,'']:
        print repr(row[' ADJAVG'])
        aavg.append(float(row[' ADJAVG']))
        std.append(float(row[' STDEV']))
        gencount.append(float(row['GENERATION']))

name =  os.path.join(os.path.dirname(os.path.abspath(sys.argv[1])), '%s.mat' % os.path.splitext(os.path.basename(sys.argv[1]))[0])
print 'Name: %s' % name
with open(name, 'w') as f:
    f.write('std = %s\n' % std)
    #f.write('avg = %s\n' % avg)
    f.write('aavg = %s\n' % aavg)
    f.write('gencount = %s\n' % gencount)
            
print "average: \n", avg
print "gencount: \n", gencount
print "adjacent average: \n", aavg
print "stddev: \n", std

